package com.boyunv.chainduty.example03;
/*
 *@description
 *
 *@author boyunv
 *@create 2023/8/26 14:28
 *@version 1.0
 */

import com.boyunv.chainduty.example02.AuthInfo;
import com.boyunv.chainduty.example02.AuthService;
import org.slf4j.Logger;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Level1AuthLink extends AuthLink{
    
    
    private Date beginDate=sdf.parse("2023-08-26 00:00:00");
    private Date endDate=sdf.parse("2023-08-31 00:00:00");
    
    public Level1AuthLink(String levelUserId, String levelUserName) throws ParseException {
        super(levelUserId, levelUserName);
    }
    
    
    @Override
    public AuthInfo doAuth(String uId, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if(null==date){
            return new AuthInfo("0001","单号:"+orderId,"状态:待一级审核人审批",levelUserName);
        }
        AuthLink next = super.getNext();
        if(next==null){
            return new AuthInfo("0001","单号:"+orderId,"状态:一级审核人审批完成","审批人:"+levelUserName);
        }
        
        if(authDate.before(beginDate)||authDate.after(endDate )){
            return new AuthInfo("0001","单号:"+orderId,"状态:一级审核人审批完成","审批人:"+levelUserName);
        }
        
        
        return next.doAuth(uId,orderId,authDate);
    }
}
